precision mediump float;


uniform vec2 u_resolution;

float line_segment_with_two_point(vec2 st, vec2 start, vec2 end, float line_width) {
    // 结束点指向起始点的向量
    vec2 lined = normalize(start) - end;
    // 起始点指向结束点的向量
    vec2 lines = - lined;
    // 结束点指向画布任意点的向量
    vec2 st_end = st - end;
    // 起始点指向画布任意点的向量
    vec2 st_start = st - start;

    float proj1 = dot(lined, lined);
    float proj2 = dot(lines, lines);
    if(proj1 > 0. && proj2 > 0.) {
        float angle = acos(dot(lined, st_end) / (length(st_end) * length(lined)));
        float dist = sin(angle) * length(st_end);
        return pow(1.0-smoothstep(0., line_width/2., dist), 6.);
    } else {
        return 0.;
    }
}

void main() {
    vec2 st = gl_FragCoord.xy / u_resolution;
    st -= 0.5;
    st *= min(u_resolution.x, u_resolution.y);
    vec3 color = vec3(0.6,0.6,1.);
    vec3 line_color = vec3(1.,0.,1.);

    float pct = line_segment_with_two_point(st, vec2(-0.1,-0.2), vec2(0.6,0.7), 0.04);

    color = mix(color, line_color, pct);
    
    gl_FragColor = vec4(color,1.);
    
    
}